
package org.openmrs.module.basicmodule.DSS.Interpreter.Function.Time;

import org.openmrs.module.basicmodule.DSS.Interpreter.Function.Function;
import java.util.*;
import java.text.*;
import org.openmrs.module.basicmodule.DSS.Interpreter.InterpreterVisitor;
import org.openmrs.module.basicmodule.DSS.ast.AST;

/**
 *
 * @author David
 */
public class AddMonthsFunction extends Function {
    @Override
    public Object execute(ArrayList args) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy");

         String date = ((AST) args.get(0)).accept(new InterpreterVisitor()).toString();
        String numDays = ((AST) args.get(1)).accept(new InterpreterVisitor()).toString();

        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(dateFormat.parse(date));
            cal.add(Calendar.MONTH, Integer.parseInt(numDays));

            return cal.getTime();
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return null;
    }
}
